/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-08-07 15:13:04
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-10 09:57:00
 */
import { observable, action } from 'mobx';
import { WeaForm, WeaTableNew } from 'comsMobx';

const { TableStore } = WeaTableNew;

export default class SearchStore {
  @observable form = new WeaForm();

  // 传入参数 获取搜索面板条件API
  // @observable conditionApi = '';

  // 传入参数 根据条件获取数据列表API
  // @observable listApi = '';

  // 搜索框类型 1：普通 2：根据公文过程动态切换公文环节
  @observable searchType = 1;

  @observable searchType_display_fw = 'none';
  @observable searchType_display_sw = 'none';
  @observable searchType_display_qb = 'none';

  @action
  getFormParams() {
    return this.form.getFormParams();
  }

  // 是否显示高级搜索面板
  @observable showSearchAd = false;

  // 表格
  @observable tableStore = new TableStore();

  @observable otherSearchParams = {};

  @observable searched = false;

  @observable keywords = [];

  @action
  setSearchCondition = (searchCondition) => {
    this.searchCondition = searchCondition;
  }

  setShowSearchAd = (showSearchAd) => {
    this.showSearchAd = showSearchAd;
  }

  setOtherSearchParams = (otherSearchParams) => {
    this.otherSearchParams = otherSearchParams;
  }

  setSearched = (searched) => {
    this.searched = searched;
  }

  setKeywords = (keywords) => {
    this.keywords = keywords;
  }

  setSearchType = (searchType) => {
    this.searchType = searchType;
  }

  setSearchType_display_fw = (searchType_display_fw) => {
    this.searchType_display_fw = searchType_display_fw;
  }

  setSearchType_display_sw = (searchType_display_sw) => {
    this.searchType_display_sw = searchType_display_sw;
  }

  setSearchType_display_qb = (searchType_display_qb) => {
    this.searchType_display_qb = searchType_display_qb;
  }

  // 高级搜索面板隐藏和显示切换
  changeShowSearchAd(b) {
    this.setShowSearchAd(b);
  }

  resetSearchForm() {
    this.setSearchType_display_fw('none');
    this.setSearchType_display_sw('none');
    this.setSearchType_display_qb('none');
    this.form.resetForm();
    this.isSearched();
  }

  isSearched() {
    this.setSearched(false);
    let { values } = Object;
    for (let value of values(this.form.getFormParams())) {
      if (value != '' && value != 0 && value != ' ' && value) {
        this.setSearched(true);
      }
    }
  }
}
